package cn.edu.scau.cmi.chenyipeng.AbstractFactory;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;

public class AbstractFactroyController {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private ChoiceBox<String> chooseBrand;

    @FXML
    private Button theB;

    @FXML
    private ChoiceBox<String> chooseMeat;

    @FXML
    private Label brandL;

    @FXML
    private Label meatL;
    
    @FXML
    private Label resultL;

    @FXML
    void createMeat(ActionEvent event) {
    	resultL.setWrapText(true);
    	CommonFactory factory = CommonFactory.getBrandFactory(chooseBrand.getValue());
    	Meat meat;
    	switch(chooseMeat.getValue()) {
    		case "beef":
    			meat = factory.makeBeef();
    			resultL.setText(resultL.getText() + "\n品牌：" + meat.getBrand() + meat.getMeat() + meat.toString());
    			break;
    		case "chicken":
    			meat = factory.makeChicken();
    			resultL.setText(resultL.getText() + "\n品牌：" + meat.getBrand() + meat.getMeat() + meat.toString());
    			break;
    		case "pork":
    			meat = factory.makePork();
    			resultL.setText(resultL.getText() + "\n品牌：" + meat.getBrand() + meat.getMeat() + meat.toString());
    			break;
    		default:
    			resultL.setText("不存在");
    			break;
    	}
    	
    }

    @FXML
    void initialize() {
        assert chooseBrand != null : "fx:id=\"chooseBrand\" was not injected: check your FXML file 'AbsFactoryUI.fxml'.";
        assert theB != null : "fx:id=\"theB\" was not injected: check your FXML file 'AbsFactoryUI.fxml'.";
        assert chooseMeat != null : "fx:id=\"chooseMeat\" was not injected: check your FXML file 'AbsFactoryUI.fxml'.";
        assert brandL != null : "fx:id=\"brandL\" was not injected: check your FXML file 'AbsFactoryUI.fxml'.";
        assert meatL != null : "fx:id=\"meatL\" was not injected: check your FXML file 'AbsFactoryUI.fxml'.";
        chooseBrand.setItems(FXCollections.observableArrayList("傲农", "天邦","温氏"));
        chooseMeat.setItems(FXCollections.observableArrayList("beef", "chicken","pork"));
    }
}
